1062B - Math - CodeForces Solution


greedy math number theory *1500

Please click on ads to support us..

Python Code:

def rozklad(wej):
    wyj = dict()
    i = 2
    while wej != 1:
        if wej % i == 0:
            wyj[i] = wyj.get(i, 0) + 1
            wej //= i
        else:
            i += 1
    return wyj
def potega(wej):
    wynik, i = 0, 1
    while i < wej:
        i *= 2
        wynik += 1
    return i, wynik
def main(wej):
    if wej == 1:
        print(1, 0)
        return
    dziel = rozklad(wej)
    maks, wynik = potega(max(dziel.values()))
    for i in dziel.values():
        if i != maks:
            wynik += 1
            break
    liczba = 1
    for i in dziel:
        liczba *= i
    print(liczba, wynik)

main(int(input()))

C++ Code:

#include<bits/stdc++.h>
#define lb long long
#define ulb unsigned long long int
using namespace std;

void solve();

int M=1e9+7;

lb inf=1e17;
bitset<500001> Pri;
vector<lb>primes;
void Sieve(lb n)
{
    Pri[0] = 1;
    for (int i = 3; i*i <= n; i += 2) {
        if (Pri[i / 2] == 0) {
            for (int j = 3 * i; j <= n; j += 2 * i)
                Pri[j / 2] = 1;
        }
    }
    for (int i = 1; i <= n; i++) {
        if (i == 2)
            primes.push_back(i);
        else if (i % 2 == 1 && Pri[i / 2] == 0)
            primes.push_back(i);
 }

}


bool is_prime(lb n)
{
    for(int i=2;i*i<=n;i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}



 /*vector<lb>pf(15000006,0),mp(15000006,0);
 lb N=15000006;
  pf[1]=1;
   for(int i=2;i<=15000000;i++)if(!pf[i])
        for(int j=i;j<=15000000;j+=i)
            if(!pf[j])
            pf[j]=i;*/
//11<<2 -> 1100; -> use 1LL << 2 if taking long long

lb count_setbit(lb n)
{
    return __builtin_popcountll(n);
    //rember ctz and clz
  //  a=__builtin_clzll(l);
   //b=__builtin_clzll(r);
}



bool is_set(lb n,lb i)
{
    n=n>>i;
    if(n%2)
        return true;
    return false;
}







void solve( int pp)
{
    lb i,n;cin>>n;
    map<lb,lb>mp;
    
    for(i=2;i<=n;i++)
    {
          while(n%i==0)
          {
            mp[i]++;
            n=n/i;
          }
    }
    lb ans=1,ma=0,ct=0;
    for(auto x:mp)
    {
        ans=ans*x.first;
        ma=max(ma,x.second);
    }
    for(i=1;i<ma;i=i*2){ct++;}
    for(auto x:mp)
    {
        if(x.second!=i){
            ct++;break;
        }
    }
    
    cout<<ans<<" "<<ct;



}



































int main()
{
   //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);

    int t;
  // cin>>t;
  t=1;
  int shiv=ceil(sqrt(1000002));
  // Sieve(100);




   int g=0;
    while(t--)
    {
   g++;
        solve(g);


   }
}


Comments

Submit
0 Comments
More Questions

1547C - Pair Programming
550A - Two Substrings
797B - Odd sum
1093A - Dice Rolling
1360B - Honest Coach
1399C - Boats Competition
1609C - Complex Market Analysis
1657E - Star MST
1143B - Nirvana
1285A - Mezo Playing Zoma
919B - Perfect Number
894A - QAQ
1551A - Polycarp and Coins
313A - Ilya and Bank Account
1469A - Regular Bracket Sequence
919C - Seat Arrangements
1634A - Reverse and Concatenate
1619C - Wrong Addition
1437A - Marketing Scheme
1473B - String LCM
1374A - Required Remainder
1265E - Beautiful Mirrors
1296A - Array with Odd Sum
1385A - Three Pairwise Maximums
911A - Nearest Minimums
102B - Sum of Digits
707A - Brain's Photos
1331B - Limericks
305B - Continued Fractions
1165B - Polycarp Training